home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-25 | 10.1 KB | 299 lines | [TEXT/CWIE] |
- //================================================================================
- // Greg Anderson
- // db+
- //
- // Cursor to a data record
- // 16 May 1994
- //================================================================================
- #pragma once
-
- #ifndef __DBPROPERTYRECORD__
- #define __DBPROPERTYRECORD__
-
- #include "DBRecord.h"
-
- //
- // Fields
- //
- // Flags
- // b31-b29: Used by AbstractDBRecord
- // b28: Clear (Set = object record)
- // b27: Set = data record (Clear = some other record)
- // b26-b16: Reserved
- // b15-b8: Encoded data type
- // b7-b0: Length of data stored in this record
- // Strings have a range of 0-12
- // Structures have a range of 0-8
- // Length byte is 0 if length is implicit (e.g. single longword) or not applicable (array of properties)
- // Length byte is 255 if data stored externally
- // Parent sibling (or parent element for property at top of tree)
- // Left sibling
- // Right sibling
- // Property ID
- //
- // Three more longwords of data
- // Data or index of record at top of element tree
- // Data or index of record at top of property tree
- // Data or type of data
- //
- // Examples:
- //
- // Longword
- // Data
- // Unused
- // Type of data (kLongType)
- //
- // Short string
- // Zero to twelve bytes, length encoded in ID of flags word
- //
- // Short typed structure
- // Zero to eight bytes, length encoded in ID of flags word
- // Type of data
- //
- // Reference to longer string, array or structure
- // Reference to data record (data record knows its own size)
- // Unused
- // Type of external data
- //
- // Array of arbitrary data (implemented as a record that contains properties of its own)
- // Unused
- // Reference to record at top of property tree
- // Type of data (kListType)
- //
- // Array of elements (implemented as a record that contains elements)
- // Reference to record at top of element tree
- // Unused
- // Type of data (kRecordType)
- //
-
- enum
- {
- kPropertyIDWord = kIDOrParentElementIndex,
- kFirstDataWord,
- kSecondDataWord,
- kThirdDataWord,
- kExternalDataIndex = kFirstDataWord,
- kTypeOfPropertyData = kThirdDataWord
- };
-
- //
- // Constants for record flags
- //
- enum
- {
- kDataTypeShift = 8,
- kInternalLengthShift = 0
- };
-
- const long kDataTypeMask = 0x0000FF00L;
- const long kInternalLengthMask = 0x000000FFL;
- const long kDataStoredExternally = kInternalLengthMask;
-
- //
- // Encoded data types
- //
- enum
- {
- //
- // A "null" type means that there is no data in the property
- //
- kEncodedNullType = 0,
-
- //
- // More general sets of data are also supported. A property record
- // may contain a set of properties OR a set of subtrees. Sets are
- // ordered by tree-insertion-order (by property ID or name), and may
- // be iterated over.
- //
- // Property sets claim to be of type "list".
- // Element sets claim to be of type "record".
- //
- kSetOfProperties,
- kSetOfElements,
-
- //
- // An external typed structure is a chunk of data whose type
- // is stored in the property record, but whose data is stored
- // in an external data block (because its length is greater than
- // 12 bytes for strings or 8 bytes for other types).
- //
- // An interal typed structure is a chunk of data stored inside
- // the property record itself.
- //
- kEncodedTypedStructure,
-
- //
- // Well-known data types:
- //
- // Currently, there is only one well-known data type: a string.
- // The purpose for having a well-known type is to avoid wasting
- // four bytes in the property record just to store the data type.
- // The data type is instead encoded in the "type" field of the
- // record word. Thus, well-known types can be up to 12 bytes long
- // before they must use external data storage, wheras other types
- // can only be 8 bytes long. (n.b. it is unnecessary to have well
- // known types for data types that will always be 8 bytes or less,
- // e.g. long integers, or for data types that will always be
- // greater than 12 bytes in length, e.g. pictures).
- //
- kFirstWellKnownType,
- kEncodedSmallStringType,
- kLastWellKnownType
- };
-
- //
- // Data types that we know about; these constants are the
- // same as those defined in AppleEvents.h, but I didn't want
- // to depend on Macintosh header files here, so I redefined
- // the constants since the set of known types is small.
- //
- enum
- {
- kNullType = 'null', // typeNull
- kLongType = 'long', // typeLongInteger
- kListType = 'list', // typeAEList
- kRecordType = 'reco', // typeAERecord
- kStringType = 'TEXT' // typeChar
- };
-
- class TDBElement;
-
- //================================================================================
- // Class TDBProperty
- //================================================================================
- class TDBProperty : public TDBRecord
- {
- //
- // A DBElement needs to maul a DBProperty that is added to it.
- //
- friend class TDBElement;
-
- //
- // ----- Fields --------------------------------------------------------------
- //
- protected:
- AConst<TDataRecord> fExternalData;
-
- //
- // ----- Methods -------------------------------------------------------------
- //
-
- public:
- TDBProperty(TDatabaseDocument* doc, long recordIndex) :
- TDBRecord(doc, recordIndex) {};
- virtual ~TDBProperty();
-
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- // Methods of TAbstractRecord:
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-
- public:
-
- virtual void FreeOwnedData(TTransaction* t);
-
- protected:
-
- virtual const TDBProperty* DBPropertyRecord() const { return this; };
-
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- // Methods of TDBRecord:
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-
- public:
-
- virtual void InitializeNewRecord(TTransaction* t);
- virtual CompareEnumeration CompareSortKeys(TTransaction* t, AConst<TDBRecord>) const;
- virtual Boolean RecordCanHaveElements(TTransaction* t) const;
- virtual Boolean RecordCanHaveProperties(TTransaction* t) const;
- virtual void RemoveFromTree(TTransaction* t);
-
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- // Public interface: const methods
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-
- public:
-
- long PropertyID(TTransaction* t) const { return this->GetRecordData(t, kPropertyIDWord); };
- long GetDataType(TTransaction* t) const;
- long GetDataLength(TTransaction* t) const;
-
- long GetLongData(TTransaction* t) const;
- void GetTypedData(TTransaction* t, TAbstractDataReference& data) const;
- CompareEnumeration Compare(TTransaction* t, const TAbstractDataReference& compareWith) const;
- CompareEnumeration Compare(TTransaction* t, AConst<TDBProperty> compareWith) const;
- Boolean Contains(TTransaction* t, const TAbstractDataReference& searchFor) const;
- Boolean Contains(TTransaction* t, AConst<TDBProperty> compareWith) const;
-
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- // Public interface: non-const methods
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-
- void SetPropertyID(TTransaction* t, long newValue) { this->ChangeRecordData(t, kPropertyIDWord, newValue); this->ResortThisRecord(t); };
-
- void MakeEmpty(TTransaction* t);
- void SetLongData(TTransaction* t, long newValue);
- void SetTypedData(TTransaction* t, const TAbstractDataReference& data);
-
- //
- // Do debugging tests on this node
- //
- virtual void Verify(TTransaction* t, Boolean verifyDeep = false) const;
-
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- // Protected interface: const methods
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-
- protected:
-
- long GetEncodedDataType(TTransaction* t) const { return ((this->RecordFlags(t) & kDataTypeMask) >> kDataTypeShift); }
- long GetInternalDataLength(TTransaction* t) const { return ((this->RecordFlags(t) & kInternalLengthMask) >> kInternalLengthShift); }
- Boolean OwnsExternalData(TTransaction* t) const { return this->GetInternalDataLength(t) == kDataStoredExternally; }
- long GetStoredDataType(TTransaction* t) const { return this->GetRecordData(t, kTypeOfPropertyData); }
- long GetExternalDataIndex(TTransaction* t) const { return this->GetRecordData(t, kExternalDataIndex); }
-
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- // Protected interface: non-const methods
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-
- public:
-
- //
- // Called by the external data record if it moves around
- //
- void SetExternalDataIndex(TTransaction* t, long externalDataIndex);
-
- protected:
-
- void SetEncodedDataType(TTransaction* t, long encodedType) { this->SetRecordFlags(t, (this->RecordFlags(t) & ~kDataTypeMask) | ((encodedType << kDataTypeShift) & kDataTypeMask)); }
- void SetInternalDataLength(TTransaction* t, long internalLength) { this->SetRecordFlags(t, (this->RecordFlags(t) & ~kInternalLengthMask) | ((internalLength << kInternalLengthShift) & kInternalLengthMask)); }
- void SetOwnsExternalData(TTransaction* t, Boolean doesOwnExternal) { this->SetInternalDataLength(t, doesOwnExternal ? kDataStoredExternally : 0); }
- void SetStoredDataType(TTransaction* t, long newStoredType) { this->ChangeRecordData(t, kTypeOfPropertyData, newStoredType); }
-
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- // Private methods:
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-
- private:
-
- AConst<TDataRecord> ExternalData(TTransaction* t) const;
- AnUpdate<TDataRecord> UpdateExternalData(TTransaction* t);
- void InformOwnerPropertyValueChanged(TTransaction* t) const;
- TConstDataReference PropertyDataReference(TTransaction* t) const;
- };
-
- //================================================================================
- // Class TDataRecordComparisonObject
- //================================================================================
- class TDataRecordComparisonObject : public TAbstractDBComparisonObject
- {
- private:
- long fSearchKey;
-
- public:
- TDataRecordComparisonObject(long searchKey) : fSearchKey(searchKey) {};
-
- virtual CompareEnumeration TestObject(TTransaction*, AConst<TDBRecord>);
- };
-
- #endif
-